import { Logger } from '@nestjs/common';
import { Request, Response, NextFunction } from 'express';

export function LoggerMiddleware(
  req: Request,
  res: Response,
  next: NextFunction,
) {
  const logger = new Logger('HTTP');
  const { method, originalUrl } = req;
  res.on('finish', () => {
    const { statusCode } = res;
    logger.log(`${method} ${originalUrl} ${statusCode}`);
  });
  next();
}
